package de.matusystems.rest

import grails.converters.JSON
import groovyx.net.http.*

class UserWebService {

	public JSON createUser(String firstname, String lastname, String email) {

		HTTPBuilder http = new HTTPBuilder(System.getenv()['CAPP_USER_SERVICE']+"/api/user")
		def jsonResponse
		def postData = ['application':1, 'firstname':firstname, 'lastname':lastname, 'email':email]

		http.request(Method.POST, groovyx.net.http.ContentType.JSON) { req ->
			body = [data:postData]
			response.success = { resp, json ->
				jsonResponse = json
			}
		}

		return jsonResponse as JSON
	}

	public JSON getUser(Long userId) {

		def jsonResponse

		HTTPBuilder http = new HTTPBuilder(System.getenv()['CAPP_USER_SERVICE']+"/api/user"+"/$userId")
		http.request(Method.GET, groovyx.net.http.ContentType.JSON) { req ->
			response.success = { resp, json ->
				jsonResponse = json
			}
		}

		return jsonResponse as JSON
	}
}
